﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ths.Components.MemberShip.DAL;
using Ths.Components.MemberShip.Entity;
using Ths.Components.SystemModule;
using Ths.SSO.Interfaces;
using Ths.SSO.Persistence;
/// <summary>
///Base 的摘要说明
/// </summary>
public class Base : System.Web.UI.Page
{
	public Base()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//

	}

    /// <summary>
    /// 绑定DropDownList
    /// </summary>
    /// <param name="ddl"></param>
    /// <param name="dataTextField"></param>
    /// <param name="dataValueField"></param>
    /// <param name="dt"></param>
    /// <param name="isFlag"></param>
    public void BindDropDownList(DropDownList ddl, string dataTextField, string dataValueField, DataTable dt,bool isFlag)
    {
        ddl.DataSource = dt;
        ddl.DataTextField = dataTextField;
        ddl.DataValueField = dataValueField;
        ddl.DataBind();
        if (isFlag)
        {
            ddl.Items.Insert(0,new ListItem("--请选择--",""));
        }
    }

    /// <summary>
    /// 根据QueryString Name返回Request值
    /// </summary>
    /// <param name="queryStringName">QueryString Name</param>
    /// <returns>Request值</returns>
    public string GetRequestStr(string queryStringName)
    {
        if (Request[queryStringName] == null)
        {
            return "";
        }
        else
        {
            return Request[queryStringName].ToString().Replace("%20", "+");
        }
    }

    public string whereClause
    {
        get
        {
            if (this.ViewState["WHERE_CLAUSE"] == null)
            {
                this.ViewState["WHERE_CLAUSE"] = "";
            }
            return Convert.ToString(this.ViewState["WHERE_CLAUSE"]);
        }
        set
        {
            this.ViewState["WHERE_CLAUSE"] = value;
        }
    }
 




    /// <summary>
    /// 
    /// </summary>
    /// <param name="alertString"></param>
    /// <param name="isClose"></param>
    /// <param name="ctl"></param>
    public void Alert(string alertString, string BeforeJsbody, string AfterJsBody, bool isClose, Control ctrl)
    {
        string _script = "";
        if (string.IsNullOrEmpty(BeforeJsbody) == false)
        {
            _script = BeforeJsbody;
        }
        if (string.IsNullOrEmpty(alertString) == false)
        {
            _script = _script + "alert('" + alertString + "');";
        }
        if (string.IsNullOrEmpty(AfterJsBody) == false)
        {
            _script = _script + AfterJsBody;
        }
        if (isClose)
        {
            _script = _script + "window.close();";
        }

        //ScriptManager p = (ScriptManager)this.Page.Master.FindControl("ScriptManager1");
        //if (p != null)
        //{

        //    System.Web.UI.ScriptManager.RegisterStartupScript(ctrl, ctrl.GetType(), "aaaa", "<script type='text/javascript'>" + _script + "</script>", false);
        //}
        //else
        //{
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script type='text/javascript'>" + _script + "</script>");
       // }
    }

    /// <summary>
    /// 提示对话框
    /// </summary>
    /// <param name="alertString"></param>
    /// <param name="ctrl"></param>
    public void Alert(string alertString, Control ctrl)
    {
        Alert(alertString, "", "", false, ctrl);
    }

    /// <summary>
    /// 提示对话框并半闭当前窗口
    /// </summary>
    /// <param name="alertString"></param>
    /// <param name="ctrl"></param>
    public void AlertClose(string alertString, string jsbody, Control ctrl)
    {
        Alert(alertString, "", jsbody, true, ctrl);
    }


    /// <summary>
    /// 运行JavaScript脚本
    /// </summary>
    /// <param name="jsbody"></param>
    /// <param name="ctrl"></param>
    public void ExecJs(string jsbody, Control ctrl)
    {
        Alert("", jsbody, "", false, ctrl);
    }

    protected override void OnLoad(EventArgs e)
    {
        if ((this.Session["username"] == null) || (base.Application[this.Session["userName"].ToString()] == null) || this.Session["StaffId"] == null)
        {
            base.Response.Write("<script language=javascript>alert('登陆超时！');window.parent.location = '../default.aspx'</script>");
        }
        else if (this.Session[this.Session["userName"].ToString()].ToString() != base.Application[this.Session["userName"].ToString()].ToString())
        {
            base.Response.Write("<script language=javascript>alert('账户在其他位置登陆，您被迫下线！');window.parent.location = '../default.aspx'</script>");
        }
        else
        {
            base.OnLoad(e);
        }
    }



 



}
